<?php

class RouteModel {
	private $startPlace;
    private $middlePlace;
	private $endPlace;
	private $name;
	private $routeNumber; //the 6 in E6.
	private $routeType; //the E in E6.
	private $vegvesenUrl;
	
	public $morningBest = false ; 
	public $midBest	= false;
	public $eveningBest = false;
	public $score = 0;
	

	public function __construct($rT, $rN, $name, $vUrl){
                $this->routeType = $rT;
                $this->routeNumber = $rN;
                $this->name = $name;
				$this->vegvesenUrl = $vUrl;
	}

	public function getStartPlace(){ return $this->startPlace; }
    public function getMiddlePlace(){ return $this->middlePlace; }
	public function getEndPlace() { return $this->endPlace; }
	public function getName() { return $this->name; }
	public function getRouteNumber() { return $this->routeNumber; }
	public function getRouteType() { return $this->routeType; }
	public function getVegvesen() {
		return utf8_encode(file_get_contents($this->vegvesenUrl, "r"));

	}
	
	public function getScore() {return $this->score;}
	
	public function calculateScores(){
	     
		if(!is_null($this->startPlace->getPeriod1())) {
		$morningScore = $this->startPlace->getPeriod1()->getWeatherSymbol() +  
						$this->middlePlace->getPeriod1()->getWeatherSymbol() + 
						$this->endPlace->getPeriod1()->getWeatherSymbol();
		}
		else $morningScore = 100;
		
		if(!is_null($this->startPlace->getPeriod2())) {
		$midScore = 	$this->startPlace->getPeriod2()->getWeatherSymbol() +  
						$this->middlePlace->getPeriod2()->getWeatherSymbol() + 
						$this->endPlace->getPeriod2()->getWeatherSymbol();
		}
		else $midScore = 100;
					
		if(!is_null($this->startPlace->getPeriod3())) {
		$eveningScore = $this->startPlace->getPeriod3()->getWeatherSymbol() +  
						$this->middlePlace->getPeriod3()->getWeatherSymbol() + 
						$this->endPlace->getPeriod3()->getWeatherSymbol();
						}
		else $eveningScore = 100;
	
		
		$this->score = $morningScore;
		$this->morningBest = true;
	//	echo "Morning er best";
		
		if($midScore < $this->score){
			$this->score = $midScore;
			$this->midBest = true;
			$this->morningBest = false;
		//	echo "Mid er best";
		}else if ($midScore == $this->score){
			$this->midBest = true;
		}
		
		if($eveningScore < $this->score){
			$this->score = $eveningScore;
			$this->eveningBest = true;
			$this->morningBest = false;
			$this->midBest= false;
		}else if ($eveningScore == $this->score){
			$this->eveningBest = true;
		}
	
	
	}
	
	public function calculateBestRoute($value){
		if($value < $this->score){
				$this->morningBest =false ; 
				$this->midBest	= false;
				$this->eveningBest = false;
		}
	}
	
	public function setName($param){ $this->name = $param; }
	public function setRouteNumber($param){ $this->routeNumber = $param; }
	public function setRouteType($param){ $this->routeType = $param; }
	public function setMiddlePlace($param){ $this->middlePlace = $param; }
	public function setStartPlace($param){ $this->startPlace = $param; }
	public function setEndPlace($param){ $this->endPlace = $param; }
}
?>